/**
 * User: alesj
 * Date: 2005.3.12
 * Time: 17:21:01
 * 
 * (C) Genera Lynx d.o.o.
 */

package com.generalynx.ecos.data.types;

import com.generalynx.common.web.tags.SelectOption;
import com.generalynx.common.resources.Resources;

import java.io.Serializable;
import java.util.Collection;
import java.util.Map;
import java.util.TreeMap;

public class Status extends IntPersistentEnum implements SelectOption {

    private int status;
    private String description;
    private static Map statusMap = new TreeMap();

    public static final Status DISABLED = new Status(-1, Resources.getString(Resources.DISABLED));
    public static final Status DEFAULT = new Status(0, Resources.getString(Resources.DEFAULT));
    public static final Status DELETED = new Status(1, Resources.getString(Resources.DELETE));

    static {
        statusMap.put(new Integer(0), DEFAULT);
        statusMap.put(new Integer(1), DELETED);
        statusMap.put(new Integer(-1), DISABLED);
    }

    public Status(int status, String description) {
        this.status = status;
        this.description = description;
    }

    public static Collection getStatuses() {
        return statusMap.values();
    }

    public String toString() {
        return getDescription() + "(" + getStatus() + ")";
    }

    protected Integer toIntegerCode() {
        return new Integer(status);
    }

    public Serializable getIdentifier() {
        return toIntegerCode();
    }

    public String getLabel() {
        return getDescription();
    }

    public boolean isAssociation() {
        return false;
    }

    public boolean isCacheable() {
        return true;
    }

    public static PersistentEnum fromSwitchCode(Object code) {
        return (PersistentEnum)statusMap.get(code);
    }

    public int getStatus() {
        return status;
    }

    public String getDescription() {
        return description;
    }

}
